<template>
  <div class="room-lobby-container">
    <!-- 移除重复的头部，因为LobbyView已经有了 -->
    <div class="lobby-actions">
      <button @click="openCreateRoomModal" class="create-room-btn">🏠 创建房间</button>
      <button @click="openJoinRoomModal" class="join-room-btn">🚪 加入房间</button>
    </div>

    <!-- 创建房间弹窗 -->
    <div v-if="showCreateRoom" class="modal-overlay" @click="closeModals">
      <div class="modal-content" @click.stop>
        <h3>创建房间</h3>

        <form @submit.prevent="createRoom" class="room-form">
          <div class="form-group">
            <label for="roomName">房间名称:</label>
            <input
              id="roomName"
              v-model="newRoom.roomName"
              type="text"
              placeholder="输入房间名称"
              required
              maxlength="20"
              autocomplete="off"
            />
          </div>

          <!-- 昵称字段 -->
          <div class="form-group">
            <label for="playerName">你的昵称:</label>
            <input
              id="playerName"
              v-model="newRoom.playerName"
              type="text"
              placeholder="输入你的昵称"
              required
              maxlength="15"
              autocomplete="off"
            />
          </div>

          <!-- 密码字段 -->
          <div class="form-group">
            <label for="roomPassword">房间密码 (可选):</label>
            <input
              id="roomPassword"
              v-model="newRoom.roomPassword"
              type="password"
              placeholder="输入房间密码（可选）"
              maxlength="20"
              autocomplete="new-password"
            />
          </div>

          <div class="form-group">
            <label for="maxPlayers">最大玩家数:</label>
            <select id="maxPlayers" v-model="newRoom.maxPlayers">
              <option value="2">2人</option>
              <option value="3">3人</option>
              <option value="4">4人</option>
              <option value="5">5人</option>
              <option value="6">6人</option>
            </select>
          </div>

          <div class="form-group">
            <label for="gameDuration">游戏时长:</label>
            <select id="gameDuration" v-model="newRoom.gameDuration">
              <option value="180">3分钟</option>
              <option value="240">4分钟</option>
              <option value="300">5分钟</option>
            </select>
          </div>

          <div class="form-actions">
            <button type="button" @click="closeModals" class="cancel-btn">取消</button>
            <button type="submit" class="submit-btn">创建房间</button>
          </div>
        </form>
      </div>
    </div>

    <!-- 加入房间弹窗 -->
    <div v-if="showJoinRoom" class="modal-overlay" @click="closeModals">
      <div class="modal-content" @click.stop>
        <h3>加入房间</h3>
        <form @submit.prevent="joinRoom" class="room-form">
          <div class="form-group">
            <label for="joinRoomCode">房间代码:</label>
            <input
              id="joinRoomCode"
              v-model="joinRoomData.roomCode"
              type="text"
              placeholder="输入房间代码"
              required
              maxlength="6"
              autocomplete="off"
            />
          </div>

          <div class="form-group">
            <label for="joinPlayerName">你的昵称:</label>
            <input
              id="joinPlayerName"
              v-model="joinRoomData.playerName"
              type="text"
              placeholder="输入你的昵称"
              required
              maxlength="15"
              autocomplete="off"
            />
          </div>

          <div class="form-group">
            <label for="joinPassword">房间密码:</label>
            <input
              id="joinPassword"
              v-model="joinRoomData.password"
              type="password"
              placeholder="输入房间密码（如果有）"
              maxlength="20"
              autocomplete="new-password"
            />
          </div>

          <div class="form-actions">
            <button type="button" @click="closeModals" class="cancel-btn">取消</button>
            <button type="submit" class="submit-btn">加入房间</button>
          </div>
        </form>
      </div>
    </div>

    <!-- 房间列表 -->
    <div class="rooms-section">
      <h3>🏠 可用房间</h3>
      <div v-if="loading" class="loading">
        <div class="spinner"></div>
        <span>加载中...</span>
      </div>
      <div v-else-if="rooms.length === 0" class="no-rooms">
        <p>暂无可用房间</p>
        <button @click="loadRooms" class="refresh-btn">🔄 刷新</button>
      </div>
      <div v-else class="rooms-grid">
        <div
          v-for="room in rooms"
          :key="room.id"
          class="room-card"
          :class="{ 'room-full': room.currentPlayers >= room.maxPlayers }"
        >
          <div class="room-header">
            <h4>{{ room.name }}</h4>
            <div class="room-header-right">
              <span class="room-code">{{ room.roomCode }}</span>
              <span v-if="room.hasPassword" class="password-protected" title="需要密码">🔒</span>
            </div>
          </div>
          <div class="room-info">
            <p>
              <span class="label">玩家:</span>
              <span class="value">{{ room.currentPlayers }}/{{ room.maxPlayers }}</span>
            </p>
            <p>
              <span class="label">时长:</span>
              <span class="value">{{ Math.floor(room.gameDuration / 60) }}分钟</span>
            </p>
            <p>
              <span class="label">状态:</span>
              <span class="value status-{{ room.status }}">{{ getStatusText(room.status) }}</span>
            </p>
          </div>
          <div class="room-actions">
            <!-- 删除按钮 - 只有房主可以删除 -->
            <button
              v-if="isRoomOwner(room)"
              @click="confirmDeleteRoom(room)"
              class="delete-btn"
              title="删除房间"
            >
              🗑️ 删除
            </button>
            <!-- 加入按钮 - 非房主显示 -->
            <button
              v-else
              @click="joinRoomByCode(room.roomCode)"
              :disabled="room.currentPlayers >= room.maxPlayers"
              class="join-btn"
            >
              {{ room.currentPlayers >= room.maxPlayers ? '房间已满' : '加入' }}
            </button>
            <!-- 临时调试按钮 - 显示房主信息 -->
            <div
              v-if="room.currentPlayers > 0"
              class="debug-info"
              style="font-size: 10px; color: #ccc; margin-top: 5px"
            >
              房主: {{ room.hostName || room.creatorName || '未知' }}
              <br />
              <span style="font-size: 8px">
                玩家数: {{ room.players?.length || 0 }}
                {{
                  room.players?.find((p) => p.isHost || p.IsHost) ? '(有房主标记)' : '(无房主标记)'
                }}
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 删除确认对话框 -->
    <div v-if="showDeleteConfirm" class="modal-overlay" @click="cancelDelete">
      <div class="modal-content delete-confirm-modal" @click.stop>
        <div class="modal-header">
          <h3>确认删除房间</h3>
          <button @click="cancelDelete" class="close-btn">×</button>
        </div>
        <div class="modal-body">
          <p>
            你确定要删除房间 <strong>"{{ roomToDelete?.name }}"</strong> 吗？
          </p>
          <p class="warning-text">⚠️ 此操作不可撤销，房间内的所有玩家将被踢出。</p>
        </div>
        <div class="modal-actions">
          <button @click="cancelDelete" class="btn btn-outline">取消</button>
          <button @click="deleteRoom" class="btn btn-danger" :disabled="deleting">
            {{ deleting ? '删除中...' : '确认删除' }}
          </button>
        </div>
      </div>
    </div>

    <!-- 错误提示 -->
    <div v-if="error" class="error-message">
      <span class="error-icon">❌</span>
      <span>{{ error }}</span>
      <button @click="error = ''" class="close-error">×</button>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 状态
const showCreateRoom = ref(false)
const showJoinRoom = ref(false)
const showDeleteConfirm = ref(false)
const loading = ref(false)
const deleting = ref(false)
const error = ref('')
const rooms = ref([])
const roomToDelete = ref(null)

// 表单数据 - 重新初始化，移除默认值
const newRoom = ref({
  roomName: '',
  maxPlayers: 4,
  gameDuration: 300,
  playerName: '',
  roomPassword: '',
})

const joinRoomData = ref({
  roomCode: '',
  playerName: '',
  password: '',
})

onMounted(() => {
  console.log('RoomLobby组件已挂载')
  console.log('newRoom初始值:', newRoom.value)

  loadRooms()

  // 强制确保所有字段都存在
  console.log('newRoom字段:', Object.keys(newRoom.value))
  console.log('newRoom.playerName:', newRoom.value.playerName)
  console.log('newRoom.roomPassword:', newRoom.value.roomPassword)

  // 确保加入房间表单为空
  joinRoomData.value = {
    roomCode: '',
    playerName: '',
    password: '',
  }
})

async function loadRooms() {
  try {
    loading.value = true
    // 调用后端API获取房间列表
    const { GameService } = await import('@/services/gameService')
    const response = await GameService.getGameList()

    console.log('API返回的原始数据:', response)

    // 确保response是数组
    const roomList = Array.isArray(response) ? response : response.data || []

    // 映射后端数据到前端格式，添加安全检查
    rooms.value = roomList.map((room) => {
      // 处理玩家列表，根据后端逻辑：第一个玩家(index=0)是房主
      const players = (room.players || room.Players || []).map((p, index) => ({
        ...p,
        nickName: p.NickName || p.nickName || p.name || p.Name || '未知玩家',
        isHost: index === 0, // 第一个玩家作为房主
        IsHost: index === 0, // 兼容大写属性名
      }))

      const mappedRoom = {
        id: room.id || room.Id || room.gameId,
        name: room.name || room.Name || room.roomName || '未命名房间',
        status: (room.status || room.Status || 'waiting').toLowerCase(),
        currentPlayers:
          players.length ||
          room.currentPlayers ||
          room.CurrentPlayers ||
          room.playerCount ||
          room.PlayerCount ||
          0,
        maxPlayers: room.maxPlayers || room.MaxPlayers || 4,
        gameDuration: room.gameDuration || room.GameDuration || 300,
        roomCode: room.code || room.Code || room.roomCode || '',
        hasPassword: room.hasPassword || room.HasPassword || false,
        players: players,
        // 添加房主信息 - 第一个玩家作为房主
        hostName: players.length > 0 ? players[0].nickName : null,
        creatorName: players.length > 0 ? players[0].nickName : null,
      }

      console.log('映射房间数据:', {
        roomId: mappedRoom.id,
        roomName: mappedRoom.name,
        playersCount: mappedRoom.players.length,
        players: mappedRoom.players.map((p, index) => ({
          index,
          id: p.id,
          nickName: p.NickName || p.nickName,
          isHost: p.IsHost || p.isHost,
          createdAt: p.createdAt || p.CreatedAt,
        })),
        hostName: mappedRoom.hostName,
        creatorName: mappedRoom.creatorName,
      })

      return mappedRoom
    })

    console.log('处理后的房间列表:', rooms.value)
  } catch (err) {
    console.error('加载房间列表失败:', err)
    error.value = err.message || '加载房间列表失败'
    // 如果API调用失败，使用空数组
    rooms.value = []
  } finally {
    loading.value = false
  }
}

async function createRoom() {
  try {
    console.log('创建房间，表单数据:', newRoom.value)

    if (!newRoom.value.roomName.trim() || !newRoom.value.playerName.trim()) {
      error.value = '请填写所有必填字段'
      return
    }

    // 保存玩家昵称到localStorage（可选）
    if (newRoom.value.playerName.trim()) {
      localStorage.setItem('playerName', newRoom.value.playerName)
    }

    // 调用后端API创建房间
    const { GameService } = await import('@/services/gameService')
    const response = await GameService.createGame({
      name: newRoom.value.roomName,
      creatorNickName: newRoom.value.playerName,
      maxPlayers: Number(newRoom.value.maxPlayers),
      gameDuration: Number(newRoom.value.gameDuration),
      password: newRoom.value.roomPassword || undefined,
    })

    console.log('创建房间成功:', response)

    // 保存玩家信息到localStorage，使用房间码作为键
    localStorage.setItem(
      `player_${response.Code}`,
      JSON.stringify({
        id: response.Players?.[0]?.id || Date.now().toString(),
        nickName: newRoom.value.playerName,
      }),
    )

    // 跳转到游戏房间，使用房间码
    router.push(`/game/${response.Code}`)
  } catch (err) {
    console.error('创建房间失败:', err)
    error.value = err.message || '创建房间失败'
  }
}

async function joinRoom() {
  try {
    if (!joinRoomData.value.roomCode.trim() || !joinRoomData.value.playerName.trim()) {
      error.value = '请填写所有必填字段'
      return
    }

    // 保存玩家昵称到localStorage（可选）
    if (joinRoomData.value.playerName.trim()) {
      localStorage.setItem('playerName', joinRoomData.value.playerName)
    }

    // 调用后端API加入房间
    const { GameService } = await import('@/services/gameService')
    const response = await GameService.joinGame(
      joinRoomData.value.roomCode,
      joinRoomData.value.playerName,
      joinRoomData.value.password || null,
    )

    console.log('加入房间成功:', response)

    // 保存玩家信息到localStorage，使用房间码作为键
    const playerId =
      response.Players?.find((p) => p.NickName === joinRoomData.value.playerName)?.Id ||
      response.Players?.find((p) => p.nickName === joinRoomData.value.playerName)?.id ||
      Date.now().toString()
    localStorage.setItem(
      `player_${response.Code}`,
      JSON.stringify({
        id: playerId,
        nickName: joinRoomData.value.playerName,
      }),
    )

    // 跳转到游戏房间，使用房间码
    router.push(`/game/${response.Code}`)
  } catch (err) {
    console.error('加入房间失败:', err)
    error.value = err.message || '加入房间失败'
  }
}

async function joinRoomByCode(roomCode) {
  try {
    // 获取玩家昵称，如果没有则提示用户输入
    let playerName = localStorage.getItem('playerName')
    if (!playerName) {
      playerName = prompt('请输入你的昵称（最多15个字符）：')
      if (!playerName || playerName.trim() === '') {
        error.value = '请输入有效的昵称'
        return
      }
      playerName = playerName.trim()
      // 保存昵称到localStorage
      localStorage.setItem('playerName', playerName)
    }

    // 查找房间信息
    const room = rooms.value.find((r) => r.roomCode === roomCode)
    if (!room) {
      error.value = '房间不存在'
      return
    }

    console.log('准备加入房间:', room)
    console.log('房间人数信息:', {
      currentPlayers: room.currentPlayers,
      maxPlayers: room.maxPlayers,
      isFull: room.currentPlayers >= room.maxPlayers,
    })

    let password = ''
    // 如果房间需要密码，提示用户输入
    if (room.hasPassword) {
      password = prompt('请输入房间密码:')
      if (password === null) {
        // 用户取消了输入
        return
      }
    }

    // 调用后端API加入房间
    const { GameService } = await import('@/services/gameService')
    const response = await GameService.joinGame(roomCode, playerName, password)

    console.log('加入房间成功:', response)

    // 保存玩家信息到localStorage，使用房间码作为键
    const playerId =
      response.Players?.find((p) => p.NickName === playerName)?.Id ||
      response.Players?.find((p) => p.nickName === playerName)?.id ||
      Date.now().toString()
    localStorage.setItem(
      `player_${response.Code}`,
      JSON.stringify({
        id: playerId,
        nickName: playerName,
      }),
    )

    // 跳转到游戏房间
    router.push(`/game/${response.Code}`)
  } catch (err) {
    console.error('加入房间失败:', err)
    error.value = err.message || '加入房间失败'
  }
}

function closeModals() {
  showCreateRoom.value = false
  showJoinRoom.value = false
  error.value = ''

  // 重置表单数据
  joinRoomData.value = {
    roomCode: '',
    playerName: '',
    password: '',
  }

  newRoom.value = {
    roomName: '',
    maxPlayers: 4,
    gameDuration: 300,
    playerName: '',
    roomPassword: '',
  }
}

function openJoinRoomModal() {
  showJoinRoom.value = true
  // 确保表单为空
  joinRoomData.value = {
    roomCode: '',
    playerName: '',
    password: '',
  }
}

function openCreateRoomModal() {
  showCreateRoom.value = true
  // 确保表单为空，使用数字类型
  newRoom.value = {
    roomName: '',
    maxPlayers: 4,
    gameDuration: 300,
    playerName: '',
    roomPassword: '',
  }
}

// 删除房间相关方法
function isRoomOwner(room) {
  // 检查当前用户是否是房主
  const currentPlayerName = localStorage.getItem('playerName')
  console.log('检查房主权限:', {
    roomId: room.id,
    roomName: room.name,
    currentPlayerName,
    players: room.players,
    playersCount: room.players?.length,
    hostName: room.hostName,
    creatorName: room.creatorName,
  })

  // 方法1: 通过房主名字判断（主要方法）
  if (room.hostName && currentPlayerName) {
    const isOwner = room.hostName === currentPlayerName
    console.log('通过房主名字判断:', { hostName: room.hostName, currentPlayerName, isOwner })
    return isOwner
  }

  // 方法2: 通过创建者名字判断（备用方法）
  if (room.creatorName && currentPlayerName) {
    const isOwner = room.creatorName === currentPlayerName
    console.log('通过创建者名字判断:', {
      creatorName: room.creatorName,
      currentPlayerName,
      isOwner,
    })
    return isOwner
  }

  // 方法3: 通过玩家列表中的第一个玩家判断（备用方法）
  if (room.players && room.players.length > 0 && currentPlayerName) {
    const firstPlayer = room.players[0]
    const firstPlayerName =
      firstPlayer.nickName || firstPlayer.NickName || firstPlayer.name || firstPlayer.Name
    const isOwner = firstPlayerName === currentPlayerName
    console.log('通过第一个玩家判断:', { firstPlayerName, currentPlayerName, isOwner })
    return isOwner
  }

  // 方法4: 临时方案 - 如果房间只有一个玩家且是当前用户，认为是房主
  if (room.currentPlayers === 1 && currentPlayerName) {
    console.log('房间只有一个玩家，临时判断为房主')
    return true
  }

  console.log('无法判断房主权限')
  return false
}

function confirmDeleteRoom(room) {
  roomToDelete.value = room
  showDeleteConfirm.value = true
}

function cancelDelete() {
  showDeleteConfirm.value = false
  roomToDelete.value = null
}

async function deleteRoom() {
  if (!roomToDelete.value) return

  try {
    deleting.value = true
    error.value = ''

    // 调用后端API删除房间
    const { GameService } = await import('@/services/gameService')
    await GameService.deleteGame(roomToDelete.value.id)

    console.log('删除房间成功')

    // 关闭确认对话框
    cancelDelete()

    // 重新加载房间列表
    await loadRooms()
  } catch (err) {
    console.error('删除房间失败:', err)
    error.value = err.message || '删除房间失败'
  } finally {
    deleting.value = false
  }
}

function getStatusText(status) {
  const statusMap = {
    waiting: '等待中',
    playing: '游戏中',
    finished: '已结束',
  }
  return statusMap[status] || status
}
</script>

<style scoped>
.room-lobby-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  min-height: calc(100vh - 80px); /* 减去导航栏高度 */
  color: white;
}

.lobby-actions {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 40px;
}

.create-room-btn,
.join-room-btn {
  padding: 15px 30px;
  font-size: 1.1rem;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: bold;
}

.create-room-btn {
  background: linear-gradient(45deg, #4caf50, #45a049);
  color: white;
}

.create-room-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(76, 175, 80, 0.4);
}

.join-room-btn {
  background: linear-gradient(45deg, #2196f3, #1976d2);
  color: white;
}

.join-room-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(33, 150, 243, 0.4);
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  color: #333;
  padding: 30px;
  border-radius: 15px;
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
  margin-bottom: 20px;
  color: #333;
  text-align: center;
  font-size: 1.5rem;
}

.room-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-weight: bold;
  color: #555;
  font-size: 0.95rem;
}

.form-group input,
.form-group select {
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-actions {
  display: flex;
  gap: 15px;
  margin-top: 20px;
}

.cancel-btn,
.submit-btn {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: bold;
}

.cancel-btn {
  background: #f5f5f5;
  color: #666;
}

.cancel-btn:hover {
  background: #e0e0e0;
}

.submit-btn {
  background: linear-gradient(45deg, #4caf50, #45a049);
  color: white;
}

.submit-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(76, 175, 80, 0.3);
}

.rooms-section {
  margin-top: 40px;
}

.rooms-section h3 {
  text-align: center;
  margin-bottom: 30px;
  font-size: 1.8rem;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  padding: 40px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top: 4px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.no-rooms {
  text-align: center;
  padding: 40px;
}

.refresh-btn {
  margin-top: 15px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.2);
  border: 2px solid white;
  color: white;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.refresh-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.room-card {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 15px;
  padding: 20px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
}

.room-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.room-card.room-full {
  opacity: 0.6;
}

.room-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.room-header h4 {
  margin: 0;
  font-size: 1.2rem;
}

.room-code {
  background: rgba(255, 255, 255, 0.2);
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: bold;
}

.room-info {
  margin-bottom: 15px;
}

.room-info p {
  margin: 8px 0;
  display: flex;
  justify-content: space-between;
}

.room-info .label {
  opacity: 0.8;
}

.room-info .value {
  font-weight: bold;
}

.status-waiting {
  color: #4caf50;
}

.status-playing {
  color: #ff9800;
}

.status-finished {
  color: #f44336;
}

.room-actions {
  text-align: center;
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
}

.join-btn {
  width: 100%;
  padding: 10px;
  background: linear-gradient(45deg, #2196f3, #1976d2);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: bold;
}

.join-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(33, 150, 243, 0.4);
}

.join-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.delete-btn {
  padding: 8px 12px;
  background: rgba(244, 67, 54, 0.8);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 1rem;
  min-width: 40px;
}

.delete-btn:hover {
  background: rgba(244, 67, 54, 1);
  transform: translateY(-2px);
  box-shadow: 0 3px 10px rgba(244, 67, 54, 0.4);
}

.delete-confirm-modal {
  max-width: 400px;
}

.delete-confirm-modal .modal-body {
  text-align: center;
  margin: 20px 0;
}

.warning-text {
  color: #ff9800;
  font-weight: bold;
  margin-top: 15px;
}

.btn-danger {
  background: linear-gradient(45deg, #f44336, #d32f2f);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: bold;
}

.btn-danger:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(244, 67, 54, 0.4);
}

.btn-danger:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.error-message {
  position: fixed;
  top: 20px;
  right: 20px;
  background: #f44336;
  color: white;
  padding: 15px 20px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1001;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.error-icon {
  font-size: 1.2rem;
}

.close-error {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  margin-left: 10px;
}

.close-error:hover {
  opacity: 0.8;
}

@media (max-width: 768px) {
  .lobby-actions {
    flex-direction: column;
    align-items: center;
  }

  .create-room-btn,
  .join-room-btn {
    width: 200px;
  }

  .rooms-grid {
    grid-template-columns: 1fr;
  }

  .modal-content {
    width: 95%;
    padding: 20px;
  }
}
</style>
